<template>
    <div class="xgdingdan">
    <div class="XgDingdan-xianzhi">
        <el-row>
            <el-col :span="24" class="dingdan-box1" style="border-bottom: 2px solid #E4E4E4">
                <div class="grid-content bg-purple-dark" style="float: left">
                    {{this.Yemian}}
                </div>
                <div style="float: right;">
                    <el-button size="mini" style="background-color: #FFFFFF" class="small-button" plain @click="returnPage"><i class="el-icon-arrow-left"></i>返回</el-button>
                    <el-button size="mini" style="background-color: #FFFFFF" class="small-button" @click="shuaxin"><i class="el-icon-refresh-right"></i>刷新</el-button>
                </div>
            </el-col>
            <el-col :span="24" class="dingdan-box1" style="margin-top: 20px">
                <div class="grid-content bg-purple-dark" style="color: black;margin-left: 30px">
                    退货商品
                </div>
                        <el-descriptions direction="vertical" :column="6" border>
                            <el-descriptions-item label="商品图片" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">
                                <img :src="Dingdan.mainImage" width="100px" height="100px">
                            </el-descriptions-item>
                            <el-descriptions-item label="商品名称" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">
                                {{Dingdan.productName}}<br/>
                                分类：{{Dingdan.categroyId}}
                            </el-descriptions-item>
                            <el-descriptions-item label="价格" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">{{Dingdan.currentpriceProduct}}</el-descriptions-item>
                            <el-descriptions-item label="编号" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">{{Dingdan.productCode}}</el-descriptions-item>
                            <el-descriptions-item label="类型" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">{{Dingdan.orderType}}</el-descriptions-item>
                            <el-descriptions-item label="小计" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">{{Dingdan.currentpriceProduct}}</el-descriptions-item>
                        </el-descriptions>
                        <div class="label-one">
                            <div style="float: right;margin-right: 80px;">
                                合计：<span style="color: #F04844">{{Dingdan.currentpriceProduct}}</span>
                            </div>
                        </div>
                        <div style="clear: both"></div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24" class="dingdan-box1" style="margin-top: 260px">
                <div class="grid-content bg-purple-dark" style="margin-left: 30px">
                    服务单信息
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="21" style="margin: 30px 0px 0px 80px;background-color: white">
                <el-descriptions direction="horizontal" :column="1" border>
                    <el-descriptions-item label="服务单号" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.orderNo}}</el-descriptions-item>
                    <el-descriptions-item label="申请状态" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.orderStatus}}</el-descriptions-item>
                    <el-descriptions-item label="订单编号" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.shopId}}</el-descriptions-item>
                    <el-descriptions-item label="申请时间" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.updateDate}}</el-descriptions-item>
                    <el-descriptions-item label="用户账号" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.account}}</el-descriptions-item>
                    <el-descriptions-item label="联系人" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.nickname}}</el-descriptions-item>
                    <el-descriptions-item label="联系电话" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.phone}} </el-descriptions-item>
                    <el-descriptions-item label="退货原因" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.ytuihuoyuanyin}}</el-descriptions-item>
                    <el-descriptions-item label="问题描述" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.wenti}}</el-descriptions-item>
                    <el-descriptions-item label="凭证照片" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">
                        <ul v-for="(item,index) in tuihuoimg":key="index">
                            <li><img :src=item width="100px" height="100px" style="float: left;margin-right: 20px"></li>
                        </ul>
                    </el-descriptions-item>
                </el-descriptions>
            </el-col>
        </el-row>
        <el-row v-if="Dingdan.orderStatus==7">
            <el-col :span="24" style="margin-top: 20px">
                <el-button type="success" style="margin: 0 10px 0px 45%" @click="handleClick">确认退货</el-button>
                <el-dialog title="操作备注" :visible.sync="dialogFormVisible" width="60%" center>
                    <div class="dialogDiv">
                        <el-form class="demo-form-inline" @submit.native.prevent ref="form">
                            <el-form-item label="操作备注" :label-width="formLabelWidth" style="width: 450px;margin-left: 150px">
                                <el-input type="textarea" v-model="beizhu" :rows="4"></el-input>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer" style="margin-left: 50%">
                            <el-button type="primary" @click="confirm">确 定</el-button>
                        </div>
                    </div>
                </el-dialog>
                <el-button type="danger" @click="handleClick">拒绝退货</el-button>
                <el-dialog title="操作备注" :visible.sync="dialogFormVisibleTwo" width="60%" center>
                    <div class="dialogDiv">
                        <el-form class="demo-form-inline" @submit.native.prevent ref="form">
                            <el-form-item label="操作备注" :label-width="formLabelWidth" style="width: 450px;margin-left: 150px">
                                <el-input type="textarea" v-model="beizhu" :rows="4"></el-input>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer" style="margin-left: 50%">
                            <el-button type="primary" @click="refuse">确 定</el-button>
                        </div>
                    </div>
                </el-dialog>
            </el-col>
        </el-row>
        <el-row v-if="Dingdan.orderStatus!=7">
            <el-col :span="21" style="margin: 30px 0px 0px 80px;background-color: white">
                <el-descriptions direction="horizontal" :column="1" border>
                    <el-descriptions-item label="订单金额" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.currentpriceProduct}}</el-descriptions-item>
                    <el-descriptions-item label="退运费" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">退运费</el-descriptions-item>
                    <el-descriptions-item label="申请退款金额" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.currentpriceProduct}}</el-descriptions-item>
                    <el-descriptions-item label="收货人姓名" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.nickname}}</el-descriptions-item>
                    <el-descriptions-item label="收获地址" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.receivingAddress}}</el-descriptions-item>
                    <el-descriptions-item label="联系电话" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.phone}} </el-descriptions-item>
                </el-descriptions>
            </el-col>
        </el-row>
        <el-row v-if="Dingdan.orderStatus!=7">
            <el-col :span="21" style="margin: 30px 0px 0px 80px;background-color: white">
                <el-descriptions direction="horizontal" :column="1" border>
                    <el-descriptions-item label="处理人员" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.accountname}}</el-descriptions-item>
                    <el-descriptions-item label="处理时间" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.chuliDate}}</el-descriptions-item>
                    <el-descriptions-item label="处理备注" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.chuliBeizhu}}</el-descriptions-item>
                </el-descriptions>
            </el-col>
        </el-row>
        <el-row v-if=Queren>
            <el-col :span="24">
                <el-button type="primary" style="margin: 20px 0px 0px 50%" @click="Shouhuo">确认收货</el-button>
            </el-col>
        </el-row>
    </div>
    </div>
</template>

<script>
    export default {
        inject:['reload'],
        data(){
            return{
                Dingdan:'',//发送搜索请求后渲染值到页面上
                formLabelWidth:"90px",
                Yemian:'',//用来表示页面是什么页面
                Queren:true,//确认收货按钮是否显示
                tuihuoimg:[], //多张图片
                dialogFormVisible:false,
                dialogFormVisibleTwo:false,
                beizhu:'',
            }
        },
        methods:{
            shuaxin(){
                //刷新页面的方法
                this.reload();
            },
            returnPage(){
                //此方法用来返回上一个页面
                if (window.history.length <= 1) {
                    this.$router.push({ path: "/system/storageManagement" });
                    return false;
                } else {
                    this.$router.go(-1);
                }
            },
            async sousuoShopDingdan(){
                //获取订单编号相关联的一切数据
                console.log(this.$store.state.TuihuoId)
                const {data:res} = await this.$http.post("/getTuihuoZhong",{
                    "orderId":this.$store.state.TuihuoId,
                })
                this.Dingdan = res;
                var str = this.Dingdan.ytuihuoimg;
                if(str != null){
                    str = str.split(",");
                }
               this.tuihuoimg = str;
                this.Dingdan.currentpriceProduct = "￥"+this.Dingdan.currentpriceProduct;
                if (this.Dingdan.orderType == 3){
                    this.Dingdan.orderType = "商品"
                }else {
                    this.Dingdan.orderType = "课程"
                }
                if(this.Dingdan.categroyId == 1){
                    this.Dingdan.categroyId = "书籍"
                }else {
                    this.Dingdan.categroyId = "服装"
                }
                if(this.Dingdan.orderStatus == 8){
                    this.Yemian = "退货申请列表-退货中";
                }else if(this.Dingdan.orderStatus == 9){
                    this.Yemian = "退货申请列表-已完成";
                    this.Queren = false;
                }else if (this.Dingdan.orderStatus == 11) {
                    this.Yemian = "退货申请列表-已拒绝";
                    this.Queren = false;
                }else if (this.Dingdan.orderStatus == 7) {
                    this.Yemian = "退货申请列表-待处理";
                    this.Queren = false;
                }
            },
            async Shouhuo(){
                const {data:res} = await this.$http.post("/getQueren",{
                    "orderId":this.Dingdan.orderId,
                    "orderStatus":9
                })
                if(res!=false){
                    this.shuaxin();
                    this.$message({
                        type: 'success',
                        message: '收货成功!'
                    })
                }
            },
            async confirm(){
                this.dialogFormVisible = false;
                const {data:res} = await this.$http.post("/getReturn",{
                    "orderId":this.Dingdan.orderId,
                    "orderStatus":8,
                    "chuliBeizhu":this.beizhu,
                    "htUserid":1,
                })
                if(res!=false){
                    this.shuaxin();
                    this.$message({
                        type: 'success',
                        message: '操作成功!'
                    })
                }
            },
            async refuse(){
                this.dialogFormVisibleTwo = false;
                const {data:res} = await this.$http.post("/getReturn",{
                    "orderId":this.Dingdan.orderId,
                    "orderStatus":11,
                    "chuliBeizhu":this.beizhu,
                })
                if(res!=false){
                    this.shuaxin();
                    this.$message({
                        type: 'success',
                        message: '操作成功!'
                    })
                }
            },
            handleClick(){
                this.dialogFormVisible = true;
                this.beizhu = ''
            },
            handleClickTwo(){
                this.dialogFormVisibleTwo = true;
                this.beizhu = ''
            }
        },
        mounted() {
            this.sousuoShopDingdan();
        }
    }
</script>

<style scoped>
    *{
        margin:0px;
        pargin:0px;
    }
    .center{
        margin:0 auto;
    }
    ul li{
        list-style:none;
    }
    a{
        text-decoration:none;
    }
    .XgDingdan-xianzhi{
        width: 1340px;
    }
    .xgdingdan{
        height: 100%;
        width: 100%;
    }
    .dingdan-box1{
        color: #666666;
        line-height: 50px;
        height: 50px;
        background-color: #F3F3F3;
    }
    .label-one{
        height: 60px;
        background-color:#F9FAFC;
        border: 1px solid #EBEEF5;
        font: bold 18px/60px "微软雅黑";
    }
    .dialogDiv{
        width: 100%;
        height: 60vh;
        overflow: scroll;
    }
</style>